<% facets_display_heading ||=  "" %>
<%# main container for facets/limits menu -%>
<div id="facets">
  <h2><%= h(facets_display_heading) %></h2>
  <% facet_field_names.each do |solr_fname| %>
    <div>
      <% display_facet = @response.facets.detect {|f| f.name == solr_fname} -%>
      <%# raise solr_fname.inspect unless display_facet -%>
      <% if display_facet && display_facet.items.length > 0 %>
        <h3 class="facet_selected"><%= facet_field_labels[solr_fname] -%></h3>
        <ul>
	      <% item_counter = 0 %>
          <% display_facet.items.each do |item| -%>
            <% if item.hits > 0 %>
              <% facet_count_for_value = facet_value_hits(@facet_lookup, solr_fname, item.value) %>
              <% if facet_in_params? solr_fname, item.value %>
                <li>
                  <span class="selected"><%= h(item.value) %> (<%= format_num facet_count_for_value %>)</span>
                  <% link_options = remove_facet_params(solr_fname, item.value, params).merge!({ controller: "catalog", action: "index" }) %>
                  [<%= link_to 'remove', url_for(link_options), class: 'remove' %>]
                </li>
                <% else %>
				<%- if item_counter > Blacklight.config[:facet_more_num] - 1 -%>
                  <li class="more">
				<%- else -%>
				  <li>
				<%- end -%>
                  <% link_options = add_facet_params(solr_fname, item.value).merge!({ controller: "catalog", action: "index" }) %>
                  <%= link_to h(item.value), url_for(link_options) %> (<%= format_num facet_count_for_value %>)
                </li>
              <% end -%>
            <% end -%>
			<% item_counter += 1 %>
          <% end %>
          <%= display_facet.items.length > Blacklight.config[:facet_more_num] ? "<li class='more_li'><a href='' class='more_link' title='more #{pluralize(2, facet_field_labels[solr_fname])[2..-1].downcase}'>more<span class='off_screen'> #{pluralize(2, facet_field_labels[solr_fname])[2..-1].downcase}</span></a></li>" : "" %>
          <%= display_facet.items.length > Blacklight.config[:facet_more_num] ? "<li class='less_li' style='display:none;'><a href='' class='more_link' title='less #{pluralize(2, facet_field_labels[solr_fname])[2..-1].downcase}'>less<span class='off_screen'> #{pluralize(2, facet_field_labels[solr_fname])[2..-1].downcase}</span></a></li>" : "" %>
        </ul>
      <% end %>
    </div>
  <% end %>
</div>
<script type="text/javascript">
  $(".more").toggle();
  $('.more_link').each(function(){
    $(this).click(function(){
      $(this).parent().parent().children("li.more").toggle();
      $(this).parent().parent().children("li.more_li").toggle();
      $(this).parent().parent().children("li.less_li").toggle();
      return false;
    });
  });
</script>
